﻿using DevExpress.Utils;
using Extensions;
using System;
using System.Drawing;

namespace ConfOrder
{
    public partial class ArticleNeed : XForm
    {
        public ArticleNeed()
        {
            InitializeComponent();
        }

        private void Tuketim_Load(object sender, EventArgs e)
        {
            MainToolbar.Visible = true;

            gridView1.Init("COGetNeed");
            gridView1.AddDetailGrid(gridView2, "ProductId");

            gridView2.Columns["ProductId"].Visible = gridView2.Columns["Scan"].Visible = false;
            gridView1.SetCaptions("QtyDepo:QtyInStock", "Durum:Comment");
            gridView2.SetCaptions("Adet:Pcs");
            gridView1.AddSummary("QtyDepo", "QtyNeeded");
            gridView2.AddSummary("Adet", "QtyNeeded");
            gridView1.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gridView1_RowCellStyle);

            gridView1.UpdateTotalSummary();
            gridView1.BestFitColumns();
            gridView2.BestFitColumns();

            gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            gridView1.MakeReadOnly();
            gridView2.MakeReadOnly();

            btnRefresh.ItemClick += btnRefresh_ItemClick;
        }

        void btnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.VeriyiGuncelle("COGetNeed");
            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.Column.FieldName == "Durum")
                e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
        }
    }
}
